#include "raft/snapshot.h"

namespace libraft {
Snapshot::Snapshot() {}

Snapshot::~Snapshot() {}

rocksdb::Status Snapshot::Open() {}

rocksdb::Status Snapshot::CreateCheckpoint(
    const std::shared_ptr<rocksdb::DB>& log_db,
    const std::string& snapshot_name, uint64_t log_size_for_flush) {
  rocksdb::Checkpoint* check_point;
  rocksdb::Checkpoint::Create(log_db.get(), &check_point);
  std::unique_ptr<rocksdb::Checkpoint> check_point_(check_point);
  rocksdb::Status s = check_point_->CreateCheckpoint(snapshot_name, log_size_for_flush);
  if (s.ok()) {
    rocksdb::DB* check_point_db;
    s = rocksdb::DB::Open(rocksdb::Options(), snapshot_name, &check_point_db);
    if (!s.ok()) {
      return rocksdb::Status::Corruption("open checkpoint failed, " +
                                         s.ToString());
    }

    std::shared_ptr<rocksdb::DB> check_point_db_(check_point_db);
    all_snapshot_dbs_[snapshot_name] = check_point_db_;
  }
  return s;
}

}  // namespace libraft
